package beans.page;

import models.common.user.DASUser;
import models.midas.form.BaseFormBean;

public class ButtonsFactoryP2 {
	
	private BaseFormBean bean;
	private DASUser user;
	
	public ButtonsFactoryP2(BaseFormBean bean, DASUser user){
		this.bean = bean;
		this.user = user;
	}
	
	private boolean hasAvailableClassLetter(){
		return true;
	}

	public AbstractButton buildSaveButton(){
		return new AbstractButton(bean, user) {
			
			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return SAVE_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				return true;
			}

		};
	}
	
	public AbstractButton buildDeclineButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return DECLINE_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {

				if ( JSON_STATE.equals("PROPOSED")) {
					if (( IS_ROLE_VARKI &&  JSON_GRAMMAR)
							||  IS_ROLE_VARMAN) {
						return true;
					}
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildNewButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return NEW_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				if (hasAvailableClassLetter()
						&& IS_ROLE_INTRA &&  IS_ROLE_MML) {
					return true;
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildCancelButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return CANCEL_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				if ( JSON_STATE.equals("PROPOSED")
						&&  IS_JSON_AUTHOR) {
					return true;
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildNewVersionButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return NEW_VER_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				if ( JSON_STATE.equals("ACCEPTED")
						&&  IS_ROLE_MML) {
					return true;
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildAddGroupButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return ADD_GRP_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				if ( JSON_STATE.equals("ACCEPTED")
						&&  IS_ROLE_MML) {
					return true;
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildABCButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return ABC_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				if ( JSON_STATE.equals("PROPOSED")
						&&  IS_ROLE_VARKI
						&&  !JSON_GRAMMAR) {
					return true;
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildEditButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return EDIT_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				if ( JSON_STATE.equals("DRAFT")
						&&  IS_JSON_AUTHOR) {
					return true;
				} else if ( JSON_STATE.equals("PROPOSED")) {
					if ( IS_ROLE_VARKI
							&&  JSON_GRAMMAR) {
						return true;
					} else if ( IS_ROLE_VARMAN) {
						return true;
					}
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildAcceptButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return ACCEPT_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				if ( JSON_STATE.equals("PROPOSED")
						&&  JSON_GRAMMAR
						&&  IS_ROLE_VARMAN) {
					return true;
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildDeleteButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return DELETE_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				if ( JSON_STATE.equals("DRAFT")
						&&  IS_JSON_AUTHOR) {
					return true;
				} else if ( JSON_STATE.equals("ACCEPTED")
						&&  IS_ROLE_VARMAN) {
					return true;
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildProposeButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return PROPOSE_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				if ( JSON_STATE.equals("DRAFT")
						&&  IS_JSON_AUTHOR) {
					return true;
				}
				return false;
			}

		};
	}
	
	public AbstractButton buildMailButton(){
		return new AbstractButton(bean, user) {

			@Override
			public boolean isVisible(Object obj) {
				return false;
			}

			@Override
			public String getButtonKey() {
				return MAIL_BUTTON_KEY;
			}

			@Override
			protected boolean isVisible() {
				return true;
			}

		};
	}
}
